package com.zb.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zb.Service.InternetService;
import com.zb.entity.Internet;
import com.zb.entity.User;
import com.zb.util.PageUtil10;

@Scope("prototype")
@Component
@RequestMapping("/inter")
public class InternetController {
	@Autowired
	private InternetService is;
	@ResponseBody
	@RequestMapping(params = "op=showinter")
	public Map<String, Object> getInterDate(HttpSession session,Integer page, Integer rows){
		User user = (User) session.getAttribute("sys_user");
		Map<String, Object> map = new HashMap<String, Object>();
		PageUtil10 pu = new PageUtil10();
		pu.setIndex(page);
		pu.setSize(rows);
		is.getPageByUid(pu, user.getId());
		map.put("total", pu.getCount());
		map.put("rows", pu.getData());
		return map;
	}
	@RequestMapping(params = "op=addinter")
	public String addInter(ModelMap modelmap,HttpSession session,Internet inter){
		User user = (User) session.getAttribute("sys_user");
		inter.setUser(user);
		is.addInternet(inter);
		modelmap.put("msg", "操作成功");
		return "internet";
	}
	@RequestMapping(params = "op=updateinter")
	public String updateInter(ModelMap modelmap,HttpSession session,Internet inter){
		User user = (User) session.getAttribute("sys_user");
		inter.setUser(user);
		if(is.updateInternet(inter)>0){
			modelmap.put("msg", "更新成功");
		}else{
			modelmap.put("msg", "更新失败");
		}
		return "internet";
	}
	@RequestMapping(params = "op=deleteinter")
	public String updateInter(int id,ModelMap modelmap){
		if(is.deleteInternet(id)>0){
			modelmap.put("msg", "删除成功");
		}else{
			modelmap.put("msg", "删除失败");
		}
		return "internet";
	}
}
